#include <bits/stdc++.h>
// 2025/03/15
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

#pragma GCC -Ofast

int t, n, m, cnt, cow[2001][2001], order[2001];
bool use[2001], have[2001][2001];

void solve(){
    cnt = n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (cow[i][j] < n && !use[i])
                order[cow[i][j]] = i, use[i] = true, cnt--;
    if (cnt) {
        cout << -1 << endl;
        return;
    }
    for (int i = 1; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (!have[order[j]][i * n + j]) {
                cout << -1 << endl;
                return;
            }
        }
    }
    for (int i = 0; i < n; i++)
        cout << order[i] << " ";
    cout << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--){
        memset(use, 0, sizeof(use));
        memset(have, 0, sizeof(have));
        cin >> n >> m;
        cnt = n;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
                cin >> cow[i][j], have[i][cow[i][j]] = true;
        solve();
    }
    return 0;
}